﻿using System;
using XCore.Logger;
using XCore.Dependency;
using XCore.Extensions;

namespace SaaS.Core.Logger
{
    public class ErrorLogger : LoggerBase, ISingletonDependency
    {
        public ErrorLogger() : base(CoreSetting.RedisConnectionString, CoreSetting.SYSTEM_ERROR, CoreSetting.LOG_INDEX)
        {

        }
        public void Log(Exception exception)
        {
            LoggerInfo ei = new LoggerInfo();
            ei.Message = exception.Message;
            ei.Properties["UserId"] = HttpContext.GetUserId();
            ei.Properties["CreationIpAddress"] = HttpContext.GetIp();
            ei.Properties["Exception"] = exception?.ToString();
            ei.Properties["StackTrace"] = exception?.StackTrace;
            ei.Properties["Appdomain"] = exception.Source;
            base.RedisLog(ei);
        }
    }
}
